﻿using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;

namespace IQIGame.Onigao.Logic
{
    public class SkillEffective_Charge : SkillEffective
    {
        protected override bool effectiveOne => true;

        protected override ISerializeCustomPOD OnExecute(SkillEffectiveData data, Unit target, SkillEffectiveContext context, int effectiveIndex, out SkillEffectiveResponse startResp)
        {
            startResp = null;
            if (data.effectiveConfig.customConfig is SkillEffective_Charge_ConfigData rConfig)
            {
                this.Execute(data, rConfig, target, context);
            }
            return null;
        }

        protected override ISerializeCustomPOD OnActionExecute(SkillEffectiveData data, SkillActionNode action, Unit target, ref SkillEffectiveContext context, int effectiveIndex)
        {
            if (action.customConfig is SkillEffective_Charge_ConfigData rConfig)
            {
                this.Execute(data, rConfig, target, context);
            }
            return null;
        }

        private void Execute(SkillEffectiveData data, SkillEffective_Charge_ConfigData config, Unit target, SkillEffectiveContext context)
        {
            var rComp = target.GetComponent<ChargeComponent>(ETComponentType.ChargeComponent);
            rComp?.StartCharge(config.chargeDuration, config.castSkill, context.selectParam, data, config.chargePrefab);
        }

#if UNITY_EDITOR
        public override string ToString(SkillCustomConfig config)
        {
            return $"蓄力释放：" + (config as SkillEffective_Charge_ConfigData)?.castSkill;
        }
#endif
    }
}